
package com.work.db.entity;

import java.io.Serializable;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.*;
import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "LEAVE_OF_ABSENCE")
public class LeaveOfAbsence extends BaseEntity implements Serializable {
	private static final long serialVersionUID = -835682074554426354L;

	@NotNull
	@Column(name = "LEAVE_TYPE", nullable = false)
	@Enumerated(EnumType.STRING)
	private LeaveTypeEnum leaveType;

	@NotEmpty
	@Column(name = "COMMENT")
	private String comment;

	@OneToOne(mappedBy = "leaveOfAbsence")
	private WorkDay dayOfLeave;

	public LeaveTypeEnum getLeaveType()
	{
		return leaveType;
	}

	public void setLeaveType(LeaveTypeEnum leaveType)
	{
		this.leaveType = leaveType;
	}

	public String getComment()
	{
		return comment;
	}

	public void setComment(String comment)
	{
		this.comment = comment;
	}

	public WorkDay getDayOfLeave()
	{
		return dayOfLeave;
	}

	public void setDayOfLeave(WorkDay dayOfLeave)
	{
		this.dayOfLeave = dayOfLeave;
	}

	public LeaveOfAbsence()
	{
		super();
	}

	public static LeaveOfAbsence emptyInstance() {
		LeaveOfAbsence instance = new LeaveOfAbsence();
		instance.setComment("");
		instance.setLeaveType(LeaveTypeEnum.URLOP_WYPOCZYNKOWY);
		
		return instance;
	}
	
	@Override
	public String toString()
	{
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
			.append("leaveType", getLeaveType())
			.append("comment", getComment())
			.append("day", getDayOfLeave().getDate())
			.toString();
	}
}